
#include <iostream>
#include <vector>
#include <algorithm>

#include <logger.hpp>
#include <xbase_utility.hpp>

using namespace std;

#include <fs.hpp>

namespace fs = xbase::fs;
using fs::path;

int main(int argc, char **argv)
{
	if(argc != 2)
	{
		cout << "usage: "
		     << argv[0]
		     << " <request_number>" << endl;
		return -1;
	}

	const int n = std::atoi(argv[1]);
	if(n <= 0)
	{
		return -1;
	}
	
	LOG_CONFIG("../../conf/log4cplus.tablet_server.conf");
	fs::init("../../conf/gfsclient.conf");

	const std::string filename("/tmp/test_delete_file/not_exists");
	const time_t start_time = cur_micro_seconds();
	for(int i=0; i<n; ++i)
	{
		fs::remove(filename);
	}
	const time_t end_time = cur_micro_seconds();

	const time_t used_time = end_time - start_time;
	int used_seconds = used_time / (1000 * 1000);
	int used_us = used_time % (1000 * 1000);
	char buf[256];
	snprintf(buf, 255, "%d.%06d", used_seconds, used_us);

	std::cout << n << " requests sent, used " << buf << " seconds" << std::endl;
	double n_per_second = ((double)n) * 1000.0 * 1000.0 / (double)used_time;
	std::cout << "average " << n_per_second << " requests per second" << std::endl;

	return 0;
}
